//
//  RankingViewController.m
//  SelfDriving
//
//  Created by apple on 16/1/16.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "RankingViewController.h"
#import "BusinessService+User.h"
@interface RankingViewController ()<UITableViewDataSource,UITableViewDelegate,BaseTableDetelage>
@property (weak, nonatomic) IBOutlet BaseTable *table;

@end

@implementation RankingViewController
{
    NSMutableArray *data;
    UILabel *notlabel;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    _table.bdelegate = self;
    data = [[NSMutableArray alloc]init];
    //xhw2018-1-12改:近期收益排名无数据
    [self initData:1];
}
-(void)initData:(int)index{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [[BusinessService shareInstance]income_sort:dic success:^(id result) {
        data = [_table result:result olddata:data index:index];
        if (notlabel) {
            [notlabel removeFromSuperview];
        }
        notlabel = (UILabel *)[_table notData];
        if (data.count == 0) {
            [self.view addSubview:notlabel];
        }
        [_table reloadData];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return data.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    LoginResponseModel *user = [data objectAtIndex:indexPath.row];
//    NSString *yuan = [ValidateHelper numberFormat:[NSString stringWithFormat:@"%@",user.total_income]];
    NSString *yuan = user.total_income;
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@元",yuan];
    
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, 30, 40)];
    lable.text =[NSString stringWithFormat:@"%ld.", indexPath.row +1];
    UILabel *namelabel = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 120, 40)];
    namelabel.text =  user.nickname;
    if (indexPath.row+1 <= 3) {
        lable.textColor = [UIColor orangeColor];
    }
    [cell.contentView addSubview:namelabel];
    [cell.contentView addSubview:lable];
    return  cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (IBAction)backActino:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
